<?php
/**
 *
 */
class login extends CI_Controller{

    public function __construct(){
      parent::__construct();
      $this->load->helper('url_helper');
      $this->load->library('session');
      $this->load->model('Mlogin');
      $this->load->model('M_updateUtil');
    }
    public function index(){
      $this->load->view('login');
    }
    public function login(){
      if($_SERVER["REQUEST_METHOD"] != "POST"){
        $this->load->view('login');
        return false;
      }
      if(empty($_POST['username'])||empty($_POST['password'])){
        $this->load->view('login');
        return false;
      }else{
        $password = $_POST['password'];
        $username = $_POST['username'];
        $utype    = $_POST['utype'];
        $flag = $this->Mlogin->getlogin($username,$password,$utype);
        if($flag){
          $userdata = array(
            'username' => $username,
            'utype'    => $utype
          );
          $this->session->set_userdata($userdata);
          echo 'success';
        }else{
          echo 'fail';
        }
      }
    }
    public function exitlogin(){
      $this->session->unset_userdata('username');
      $this->session->unset_userdata('utype');
      redirect('/login');
    }
    public function insertmore(){
      $this->load->view('inserttest');
    }
    public function insertgo(){
      if($this->Mlogin->insertgo($_GET['time'],$_GET['emid'])){
        echo true;
      }else{
        echo false;
      }
    }
    public function outsummarygo(){
      $json = $this->Mlogin->outsummarygo();
      // echo '111';
      header('Content-type:text/plain;charset=utf-8');
      header('Content-Disposition:attachment;filename="hello.txt"');
      print_r($json);
    }
}
